package com.mall.service;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mall.db.api.SmsCouponHistoryApi;
import com.mall.pageResult.PageResult;
import com.mall.pojo.SmsCouponHistory;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

@Service
public class CouponHistoryService {

    @DubboReference
    private SmsCouponHistoryApi couponHistoryApi;

    /**
     * 根据优惠券id，使用状态，订单编号分页获取领取记录
     * @param pageNum
     * @param pageSize
     * @param couponId
     * @param useStatus
     * @param orderSn
     * @return
     */
    public PageResult<SmsCouponHistory> list(Integer pageNum, Integer pageSize, Integer couponId, Integer useStatus, String orderSn) {
        //根据优惠券id，使用状态，订单编号分页获取领取记录
        Page<SmsCouponHistory> page = couponHistoryApi.list(pageNum,pageSize,couponId,useStatus,orderSn);
        //组装返回结果数据
        PageResult<SmsCouponHistory> result = new PageResult<>();
        result.setPageNum(pageNum);
        result.setPageSize(pageSize);
        result.setList(page.getRecords());
        result.setTotal(Convert.toInt(page.getTotal()));
        result.setTotalPage(Convert.toInt(page.getPages()));
        return result;
    }
}
